#!/bin/sh
#
# start-all -- start all stopped docker lab
#

TOP_DIR=$(cd $(dirname $0)/../../ && pwd)

id_names=`docker ps -a --format='{{.ID}},{{.Names}}' | sed '1!G;h;$!d'`

for id_name in $id_names
do
    id=$(echo $id_name | cut -d ',' -f1)
    name=$(echo $id_name | cut -d ',' -f2)
    lab_name=${name%-*}

    echo "Starting $name ..."

    ls ${TOP_DIR}/output/$name*/ >/dev/null 2>&1

    if [ $? -eq 0 ]; then
        ${TOP_DIR}/output/$name*/tools/docker/start $lab_name
    elif [ -d ${TOP_DIR}/configs/$lab_name ]; then
        ${TOP_DIR}/tools/docker/start $lab_name
    else
        docker start $id
    fi
done
